---
apiVersion: batch/v1
kind: Job
metadata:
  name: platformdb-remove-job
  namespace: {{ namespace }}
spec:
  selector:
    matchLabels:
      job-name: platformdb-remove-job
  template:
    metadata:
      creationTimestamp: null
      labels:
        job-name: platformdb-remove-job
    spec:
      imagePullSecrets:
      - name: {{ image_pull_secret }}
      containers:
      - name: platformdb-remove-job
        image: {{ image_registry.addr }}/{{ image_registry.project }}/skiff-tools:v1.4-20200525
        command: ['sh', '-c', 'echo "all db removed completed"']
        imagePullPolicy: IfNotPresent
      restartPolicy: Never
      initContainers:
{% for sql in mysql %}
      - name: {{ mysql[sql]['dbname'] | replace('_', '-')}}
        image: {{ image_registry.addr }}/{{ image_registry.project }}/skiff-tools:v1.4-20200525
        imagePullPolicy: IfNotPresent
        command:
        - bash
        - -c
        - "mysql -h {{ mysql[sql]['host'] }} -P {{ mysql[sql]['port'] }} -u {{ mysql[sql]['user']}} -p{{mysql[sql]['passwd']}} -e 'DROP DATABASE IF EXISTS {{ mysql[sql]['dbname'] }};'"
{% endfor %}
